// pages/kc_detail/kc_detail.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    build_image:"https://sign-face.oss-cn-shanghai.aliyuncs.com/img/test.jpg",
    location_name:"教五楼",
    course_name:"Java",
    teacher_username:"无无无",
    scores:"4.6",
    location_x:"106.88",
    location_y:"88.88",
    location_describe:"无无无无无无无无",
    describe:"无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无",
    com_list:[ ],
    sub_scores:'',
    texts:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    
    wx.request({
      url: app.globalData.url + 'v1/records/', 
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {},
      success (res) {
        //console.log(res),
        that.setData({
          com_list: res.data.records.reverse(),
        })
      }
    })

    //根据id和courseId查一条records
    wx.request({
      //更改cid
      url: app.globalData.url + 'v1/records/'+app.globalData.userInfo.id+'/62bce151-fa1f-44ea-bcb2-7c8284f17ae6', 
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {},
      success (res) {
        console.log(res),
        app.globalData.records = res.data.records
        console.log(app.globalData.records)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //返回上一页
  backlast (){
    wx.navigateBack({
      delta: 1
    })
  },

  //跳转到签到页
  goSignPage (){
    wx.navigateTo({
      url: "/pages/signPage/signPage",
    })
  },
  //显示评论
  show_comments:function(){
    let that = this
    wx.request({
      url: app.globalData.url + 'v1/records/', 
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {},
      success (res) {
        //console.log(res),
        that.setData({
          com_list: res.data.records.reverse(),
        })
      }
    })
  },

  //修改评论
  addMsg:function(e){
    let that = this
    let scores = e.detail.value.scores
    let comments = e.detail.value.remark
    app.globalData.records.scores = scores
    app.globalData.records.comments = comments
    //console.log(app.globalData.records)
    wx.request({
      method: "post",
      url: app.globalData.url + 'v1/records/update', 
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: app.globalData.records,
      success (res) {
        console.log(res)
        that.show_comments()
      }
    })
  }
})